package com.satchi.struts.action.customeraction;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.satchi.hib.pojo.FinCustomer;
import com.satchi.service.GetCustomerService;
import com.satchi.struts.ActionHelper;

public class ForwardCustomeraddAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		GetCustomerService serv = new GetCustomerService();
		List<FinCustomer> parents;
		String parentId = request.getParameter("p");
		if (ActionHelper.IsEmpty(parentId)) {
			parents = serv.getAllParentCustomer();
		}else{
			parents = new ArrayList<FinCustomer>();
			parents.add(serv.get(parentId));
		}
		request.setAttribute("parentCustomers", parents);
		return mapping.findForward(ActionHelper.SUCCESS);
	}
}
